<template>
	<view style="display: flex;flex-direction: column;height: 100vh;justify-content: space-between; ">
		<view>
			<view @click="userInfo"
				style="padding: 10px;display: flex;justify-content: space-between; color: #FFFFFF;background-color: #000000;border-bottom: 1px solid #aaa;">
				<u-avatar :src="userAvatar"></u-avatar>
				<view style="margin-left: 10px;display: flex;flex-direction: column;justify-content: space-around;flex: 1;">
					<view>{{userNickName}}</view>
					<view>189****1234</view>
				</view>
				<view style="color: #FFFFFF;background-color: #000000; margin: auto;">
					Test门店223 >
				</view>
			</view>
			
		</view>
		<view class="map">
			<view style="text-align: center;color: #2B85E4;font-weight: bold;position: fixed;left: 0;right: 0;margin-top: 10rpx;">
				科斯特Mes数据中心
			</view>
			<view style="margin-top: 50rpx ;">
				<mapdemo></mapdemo>
			</view>
		</view>
		<view style="background-color: #AAAAAA;display: flex; justify-content: space-between;flex-wrap: wrap;">
			<view class="box" @click="order">
				<view>订单中心</view>
				<view>Order Center</view>
			</view>
			<view class="box" @click="notice">
				<!-- <image src="../../../static/image/bk.png" style="width: 100%;height: 67px;;"></image> -->
				<view>公告中心</view>
				<view>Announcement Center</view>
			</view>
			<view class="box">
				<view>促销中心</view>
				<view>Promotion Center</view>
			</view>
			<view class="box">
				<view>学习中心</view>
				<view>Learning Center</view>
			</view>
		</view>

	</view>

</template>

<script>
	import mapdemo from './map.vue'
	export default {
		components: {
			mapdemo
		},
		data() {
			return {
				text: '无头像',
				userNickName: '',
				userAvatar: '',
				isCanUse: false,
				loaclOpenId:''
			};
		},
		onLoad() {
			this.loaclOpenId = uni.getStorageSync('loaclOpenId');
			
			if(!this.loaclOpenId){
				// uni.reLaunch({
				// 	url: '/pages/btdm/index/login/index'
				// });
			}
			let _this = this;
			_this.login()
			// uni.getStorage({
			// 	key: 'isCanUse',
			// 	success(res){
			// 		_this.isCanUse = res.data
			// 		console.log(_this.isCanUse)
			// 	}
			// })
			// setTimeout(()=>{
			// 	if(_this.isCanUse == true){
			// 		_this.login()
			// 	}else{
			// 		uni.showToast({
			// 			title:'您已授权',
			// 			icon:'error',
			// 			duration:2000
			// 		})
			// 	}
			// },100)






			// uni.login({
			// 	provider: 'weixin',
			// 	success: function(loginRes) {
			// 		console.log(loginRes, 'loginRes====');
			// 		uni.request({
			// 			url: 'https://api.weixin.qq.com/sns/jscode2session', // 请求微信服务器
			// 			method: 'GET',
			// 			data: {
			// 				appid: 'wxddbed78734cf3c49', //你的小程序的APPID
			// 				secret: '9d555e4f9cd5e1f772281678112ba140', //你的小程序秘钥secret,  
			// 				js_code: loginRes.code, //wx.login 登录成功后的code
			// 				grant_type: 'authorization_code' //此处为固定值
			// 			},
			// 			success: (res) => {
			// 				console.log('获取信息', res);
			// 			}
			// 		});

			// 		// console.log(loginRes.authResult);
			// 		// 获取用户信息
			// 		// uni.getUserInfo({
			// 		// 	provider: 'weixin',
			// 		// 	success: function(infoRes) {
			// 		// 		console.log(infoRes.userInfo)
			// 		// 		console.log('用户昵称为：' + infoRes.userInfo.nickName);
			// 		// 		_this.userNickName = infoRes.userInfo.nickName;
			// 		// 		_this.userAvatar = infoRes.userInfo.avatarUrl;
			// 		// 	},
			// 		// 	fail(e) {
			// 		// 		console.log(e)
			// 		// 	}
			// 		// });
			// 	}
			// });
		},
		methods: {
			login() {
				let _this = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes, 'loginRes====');
						uni.request({
							url: 'https://api.weixin.qq.com/sns/jscode2session', // 请求微信服务器
							method: 'GET',
							data: {
								appid: 'wxddbed78734cf3c49', //你的小程序的APPID
								secret: '9d555e4f9cd5e1f772281678112ba140', //你的小程序秘钥secret,  
								js_code: loginRes.code, //wx.login 登录成功后的code
								grant_type: 'authorization_code' //此处为固定值
							},
							success: (res) => {
								console.log('获取信息', res);
							}
						});

						uni.getUserInfo({
							provider: 'weixin',
							success: function(infoRes) {
								console.log('用户昵称为：=======', infoRes);
								_this.userNickName = infoRes.userInfo.nickName;
								_this.userAvatar = infoRes.userInfo.avatarUrl;
							}
						});

						// 获取用户信息
						// uni.getUserProfile({
						// 	desc: '登录后可同步数据',
						// 	success: (infoRes) => {
						// 		console.log(infoRes, 'getUserProfile=====')
						// 		// console.log('用户昵称为：' + infoRes.userInfo.nickName);
						// 		_this.userNickName = infoRes.userInfo.nickName;
						// 		_this.userAvatar = infoRes.userInfo.avatarUrl;
						// 	},
						// 	fail: (err) => {
						// 		console.log(err,'err错误===');
						// 		uni.showToast({
						// 			title: '授权已取消',
						// 			icon: 'error',
						// 			mask: true,
						// 		});
						// 	},
						// });
					}
				});
			},
			userInfo() {
				uni.navigateTo({
					url: '/pages/btdm/index/user/userInfo',
				})
			},
			order() {
				uni.navigateTo({
					url: '/pages/btdm/index/index/home',
				})
			},
			notice() {
				uni.navigateTo({
					url: '/pages/btdm/index/notice/notice',
				})
			},
			getUserInfo(event) {
				let _this = this;
				uni.getUserProfile({
					desc: '登录后可同步数据',
					success: (infoRes) => {
						console.log(infoRes, 'getUserProfile=====')
						// console.log('用户昵称为：' + infoRes.userInfo.nickName);
						_this.userNickName = infoRes.userInfo.nickName;
						_this.userAvatar = infoRes.userInfo.avatarUrl;
					},
					fail: (err) => {
						console.log(err,'err错误===');
						uni.showToast({
							title: '授权已取消',
							icon: 'error',
							mask: true,
						});
					},
				});
			},
			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX
			},

			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
			},

			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target
				} else {
					this.modalName = null
				}
				this.listTouchDirection = null
			},
			/**
			 * 请求静态数据只是为了代码不那么乱
			 * 分次请求未作整合
			 */
			async loadData() {

			},
			navToDetailUrl(char) {

			},
		},
	}
</script>

<style lang="scss">
	.map {
		// flex: 1;
		height: 100%;
		background-color: #aaa;
		background: url('../../../static/image/bg.jpg') center;
		background-size: cover;
		overflow: scroll;
	}

	.box {
		width: 49.8%;
		height: 67px;
		text-align: center;
		padding: 10px;
		color: #FFFFFF;
		background: url('') no-repeat center;
		background-size: cover;
	}

	// /* #ifdef MP */
	page {
		.cate-section {
			position: relative;
			z-index: 5;
			border-radius: 16upx 16upx 0 0;
			margin-top: -20upx;
		}

		.carousel-section {
			padding: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				left: 45upx;
				bottom: 40upx;
			}
		}

		text {
			font-size: 60upx;
		}
	}

	// /* #endif */
	page {
		background: #ffffff;
	}
</style>